#pragma once
#include <string>
#include <map>
#include "libutilsbase.h"
using namespace System;
using namespace System::Collections::ObjectModel;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::Generic;

public 	ref struct
CastHelper
{
public:
	generic <typename Target>
	Target CastToNet(IntPtr source) 
	{
		Target ret = (Target)Marshal::PtrToStructure(source,Target::typeid);
		return ret;
	}

	/*IntPtr GetGlobMemory()
	{
		static IntPtr ptr = Marshal::AllocHGlobal(1024*1024);
		return ptr;
	}*/


	template<typename TargetNative,typename SourceNet> 
	TargetNative CastToNative(SourceNet source)
	{
		IntPtr ptr = Marshal::AllocHGlobal(1024*1024);
		Marshal::StructureToPtr(source,ptr,false);

		TargetNative ret = *((TargetNative*)(void*)ptr);
		Marshal::FreeHGlobal(ptr);
		return ret;
	}

public:
	static std::string Cast_std_string (System::String^ s);
	static std::wstring Cast_std_wstring (System::String ^ s);

	static System::String^ Cast_String(const char* s);
	static System::String^ Cast_String(const wchar_t* s);

	static System::String^ Cast_String(const std::string& s);
	static System::String^ Cast_String(const std::wstring& s);

public:
	Dictionary<System::String^,System::String^>^ ToNetMap( const std::map<tstring,tstring>& _map );


	std::map<tstring,tstring> ToMap( Dictionary<System::String^,System::String^>^ input );

};

